<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--#include file="ErrorHandler.asp" -->
<% on error resume next %>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Save Report</title>
<link href="UniversalStyleSheet.css" rel="stylesheet" type="text/css" />

<script type="text/javascript">
function Savesubmit(){
fn=document.getElementById("FileName").value
if (fn ==""){return;}
fn.replace(" ","+")
window.location.href="SaveReport.asp?ac=save&filename=" + fn + "&fromfull=<%= request.QueryString("fromfull") %>&tofull=<%= request.QueryString("tofull")%>"
}
</script> 
</head>

<body>
<%
ac=request.QueryString("ac")

select case ac
	case ""
	
		Fromfull=request.QueryString("fromfull")
		Tofull=request.QueryString("tofull")
		filename=request.QueryString("filename")
		ticketcount=request.QueryString("ticketcount")
		set db=server.CreateObject("adodb.connection")
		set rs=server.CreateObject("adodb.recordset")
		filepath=server.MapPath("/afterhours/access/backend/admin.mdb")
		sql="select top 1 filenameformat from excel"
		db.open ("provider=microsoft.jet.oledb.4.0;data source=" & filepath)
		rs.open sql,db,1,2
		fileformat=rs("filenameformat")
		filename=replace(fileformat,"<start date>",fromfull)
		filename=replace(filename,"<end date>",tofull)
		filename=replace(filename,"<ticket count>",ticketcount)
		rs.close
		db.close
		set rs=nothing
		set db=nothing
		if err.number<>0 then errorhandler("no")

%>	
<table width="370" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="20" height="20" background="Images/TableUpperLeft.png"></td>
    <td width="330" height="20" background="Images/TableUpperMiddle.png"></td>
    <td width="20" height="20" background="Images/TableUpperRight.png"></td>
  </tr>
  <tr>
    <td width="20" background="Images/TableMiddleLeft.png"></td>
    <td bgcolor="#FFFFFF">
	<iframe id="SaveReportData" name="SaveReportData" src="SaveReportFileData.asp" width="330" height="210"></iframe>
	
	  <span class="SearchFormText">FileName</span><br/>
	  <input name="FileName" type="text" id="FileName" value="<%= filename %>" size="40" />
      <input name="BtnSave" type="image" class="buttons" id="BtnSave" onclick="Savesubmit()" value="Save" src="Images/SaveButton_small.png" align="bottom"/>
	
	</td>
    <td width="20" background="Images/TableMiddleRight.png"></td>
  </tr>
  <tr>
    <td width="20" height="20" background="Images/TableLowerLeft.png"></td>
    <td width="330" height="20" background="Images/TableLowerMiddle.png"></td>
    <td width="20" height="20" background="Images/TableLowerRight.png"></td>
  </tr>
</table>
<% 
	case "save"

		function nz(EvalString,NullReturn)
		if (isnull(EvalString)) or (EvalString="") then
			NZ=NullReturn
		else
			NZ=EvalString
		end if
		end function

		application.Lock()

		Fromfull=request.QueryString("fromfull")
		Tofull=request.QueryString("tofull")
		filename=request.QueryString("filename")
		
		dim Tdb,Trs,Ndb,Nrs,Cdb,Crs,entry()
		set Tdb=server.CreateObject("adodb.connection")
		set Trs=server.CreateObject("adodb.recordset")

		Tfilepath=server.MapPath("/afterhours/access/backend/tickets.mdb")

		Tdb.open ("provider=microsoft.jet.oledb.4.0;data source=" & Tfilepath)

		Tsql="select * from tickets where created_time between #" & Fromfull & "# and #" & Tofull & "# order by created_time, emergency"
		Trs.open Tsql,Tdb,1,2
		if Trs.eof then 
			results = r
			found="do it anyway"
			ticketcount=0
			listlength=-1
		else
			Tra=Trs.getrows()
			for x=0 to ubound(Tra,2)
				Tcids=Tcids & "'" & Tra(1,x) & "',"
				Tids=Tids & Tra(0,x) & ","
				ticketcount=ticketcount+1
			next 

			Tcids=left(Tcids,len(Tcids)-1)
			Tids=left(Tids,len(Tids)-1)
	
			set Ndb=server.CreateObject("adodb.connection")
			set Cdb=server.CreateObject("adodb.connection")
			set THdb=server.CreateObject("adodb.connection")
	
			set Nrs=server.CreateObject("adodb.recordset")
			set Crs=server.CreateObject("adodb.recordset")
			set THrs=server.CreateObject("adodb.recordset")
	
			Nfilepath=server.MapPath("/afterhours/access/backend/tickets.mdb")
			Cfilepath=server.MapPath("/afterhours/access/backend/homesmart_customers.mdb")
			THfilepath=server.MapPath("/afterhours/access/backend/tickets.mdb")
	
			Ndb.open ("provider=microsoft.jet.oledb.4.0;data source=" & Nfilepath)
			Cdb.open ("provider=microsoft.jet.oledb.4.0;data source=" & Cfilepath)
			THdb.open ("provider=microsoft.jet.oledb.4.0;data source=" & THfilepath)
			
			Nsql="select * from non_Homesmart_customers where contract_id in (" & Tcids & ")"
			Csql="select * from customers where contract_id in (" & Tcids & ")"
			THsql="select * from ticket_history where ticket_id in (" & Tids & ")"
	
			Nrs.open Nsql,Ndb,1,2
			if err.number<>0 then errorhandler("no")
			if Nrs.eof then
				Nons="none"
			else
				Nra=Nrs.getrows()
			end if
			Nrs.close
			Ndb.close
			set Nrs=nothing
			set Ndb=nothing
	
			Crs.open Csql,Cdb,1,2
			if Crs.eof then
				Custs="none"
			else
				Cra=Crs.getrows()
			end if
			Crs.close
			Cdb.close
			set Crs=nothing
			set Cdb=nothing
	
			THrs.open THsql,THdb,1,2
			if err.number<>0 then errorhandler("no")
			if THrs.eof then
				redim THra(0,0)
				THra(0,0)=""
			else
				THra=THrs.getrows()
			end if
			THrs.close
			THdb.close
			set THrs=nothing
			set THdb=nothing
	
			'create entrys
			redim entrys(14,ubound(Tra,2))
			for y=0 to ubound(Tra,2)
				'ticket info. from Tra we take 0,2,3,4,9,6,7
				entrys(0,y)=nz(Tra(0,y),"&nbsp;")
				entrys(1,y)=nz(Tra(2,y),"&nbsp;")
				entrys(2,y)=nz(Tra(3,y),"&nbsp;")
				entrys(3,y)=nz(Tra(4,y),"&nbsp;")
				entrys(4,y)=nz(Tra(9,y),"&nbsp;")
				entrys(5,y)=nz(Tra(6,y),"&nbsp;")
				entrys(6,y)=nz(Tra(7,y),"&nbsp;")
	
				'cust info. from cust we take acct, fname lname, addr, city, zip, phone
				if isnumeric(left(Tra(1,y),1)) then 'is cust
					for z=0 to ubound(Cra,2)
						if Cra(1,z)=Tra(1,y) then
							entrys(7,y)=nz(Cra(0,z),"&nbsp;")
							entrys(8,y)=nz(Cra(2,z),"&nbsp;") & " " & nz(Cra(3,z),"&nbsp;")
							entrys(9,y)=nz(Cra(4,z),"&nbsp;")
							entrys(10,y)=nz(Cra(5,z),"&nbsp;")
							entrys(11,y)=nz(Cra(7,z),"&nbsp;")
							entrys(12,y)=nz(Cra(8,z),"&nbsp;")
							exit for
						end if
					next
				else 'is non cust
					for z=0 to ubound(Nra,2)
						if Nra(1,z)=Tra(1,y) then
							entrys(7,y)=nz(Nra(0,z),"&nbsp;")
							entrys(8,y)=nz(Nra(2,z),"&nbsp;") & " " & nz(Nra(3,z),"&nbsp;")
							entrys(9,y)=nz(Nra(4,z),"&nbsp;")
							entrys(10,y)=nz(Nra(5,z),"&nbsp;")
							entrys(11,y)=nz(Nra(7,z),"&nbsp;")

							entrys(12,y)=nz(Nra(8,z),"&nbsp;")
							exit for
						end if
					next
				end if
		
				'ticket history 2 user, 3 when, 4 note
				temp=""
				tc=0
				for z=0 to ubound(THra,2) 
					if THra(1,z)=Tra(0,y) then
						tc=tc+1
						spc=""
						for spccnt=1 to len(tc & ". ")+1
							spc=spc & "&nbsp;"
						next 
						temp=temp & "<br>" & "<b>" & tc & ". (" & THra(2,z) & " - " & THra(3,z) & ")</b>" & "<br>"& spc & "<i>" & THra(4,z) & "</i>" & "<br>"& "<br>"
					end if
				next 
				entrys(13,y)=nz(temp,"&nbsp;")
				entrys(14,y)=nz(tc,"&nbsp;")
			next 
			listlength=ubound(entrys,2)
			ticketcount=listlength+1
		end if
		Trs.close
		Tdb.close
		set Trs=nothing
		set Tdb=nothing
		application.UnLock()
		'0 ticket id, 1 status, 2 given to, 3 created time, 4 dispatched time, 5 appliance, 6 emergency, 7 acct number, 8 name, 9 address, 10 city, 11 zip, 12 phone, 13 ticket history, 14 num of calls
		if found<>"none" then

'begin create report
r=r & "<html xmlns:o='urn:schemas-microsoft-com:office:office'" & vbcrlf
r=r & "xmlns:x='urn:schemas-microsoft-com:office:excel'" & vbcrlf
r=r & "xmlns='http://www.w3.org/TR/REC-html40'>" & vbcrlf
r=r & "<head>" & vbcrlf
r=r & "<meta http-equiv=Content-Type content='text/html; charset=us-ascii'>" & vbcrlf
r=r & "<meta name=ProgId content=Excel.Sheet>" & vbcrlf
r=r & "<meta name=Generator content='Microsoft Excel 10'>" & vbcrlf
r=r & "<title>AfterHours Ticket Report Data</title>" & vbcrlf
r=r & "<!--[if gte mso 9]><xml>" & vbcrlf
r=r & " <o:DocumentProperties>" & vbcrlf
r=r & "  <o:LastAuthor>AlphaPage HomeSmart ticket auto-report</o:LastAuthor>" & vbcrlf
r=r & "  <o:LastSaved>2006-07-07T03:23:06Z</o:LastSaved>" & vbcrlf
r=r & "  <o:Version>10.3501</o:Version>" & vbcrlf
r=r & " </o:DocumentProperties>" & vbcrlf
r=r & " <o:OfficeDocumentSettings>" & vbcrlf
r=r & "  <o:DownloadComponents/>" & vbcrlf
r=r & "   </o:OfficeDocumentSettings>" & vbcrlf
r=r & "</xml><![endif]-->" & vbcrlf
r=r & "<style>" & vbcrlf
r=r & "<!--table" & vbcrlf
r=r & "	{mso-displayed-decimal-separator:'\.';" & vbcrlf
r=r & "	mso-displayed-thousand-separator:'\,';}" & vbcrlf
r=r & "@page" & vbcrlf
r=r & "	{margin:.5in .5in .5in .5in;" & vbcrlf
r=r & "	mso-header-margin:0in;" & vbcrlf
r=r & "	mso-footer-margin:0in;" & vbcrlf
r=r & "	mso-page-orientation:landscape;}" & vbcrlf
r=r & "tr" & vbcrlf
r=r & "	{mso-height-source:auto;}" & vbcrlf
r=r & "col" & vbcrlf
r=r & "	{mso-width-source:auto;}" & vbcrlf
r=r & "br" & vbcrlf
r=r & "	{mso-data-placement:same-cell;}" & vbcrlf
r=r & ".style0" & vbcrlf
r=r & "	{mso-number-format:General;" & vbcrlf
r=r & "	text-align:general;" & vbcrlf
r=r & "	vertical-align:bottom;" & vbcrlf
r=r & "	white-space:nowrap;" & vbcrlf
r=r & "	mso-rotate:0;" & vbcrlf
r=r & "	mso-background-source:auto;" & vbcrlf
r=r & "	mso-pattern:auto;" & vbcrlf
r=r & "	color:windowtext;" & vbcrlf
r=r & "	font-size:10.0pt;" & vbcrlf
r=r & "	font-weight:400;" & vbcrlf
r=r & "	font-style:normal;" & vbcrlf
r=r & "	text-decoration:none;" & vbcrlf
r=r & "	font-family:Arial;" & vbcrlf
r=r & "	mso-generic-font-family:auto;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	border:none;" & vbcrlf
r=r & "	mso-protection:locked visible;" & vbcrlf
r=r & "	mso-style-name:Normal;" & vbcrlf
r=r & "	mso-style-id:0;}" & vbcrlf
r=r & "td" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	padding-top:1px;" & vbcrlf
r=r & "	padding-right:1px;" & vbcrlf
r=r & "	padding-left:1px;" & vbcrlf
r=r & "	mso-ignore:padding;" & vbcrlf
r=r & "	color:windowtext;" & vbcrlf
r=r & "	font-size:10.0pt;" & vbcrlf
r=r & "	font-weight:400;" & vbcrlf
r=r & "	font-style:normal;" & vbcrlf
r=r & "	text-decoration:none;" & vbcrlf
r=r & "	font-family:Arial;" & vbcrlf
r=r & "	mso-generic-font-family:auto;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	mso-number-format:General;" & vbcrlf
r=r & "	text-align:general;" & vbcrlf
r=r & "	vertical-align:bottom;" & vbcrlf
r=r & "	border:none;" & vbcrlf
r=r & "	mso-background-source:auto;" & vbcrlf
r=r & "	mso-pattern:auto;" & vbcrlf
r=r & "	mso-protection:locked visible;" & vbcrlf
r=r & "	white-space:nowrap;" & vbcrlf
r=r & "	mso-rotate:0;}" & vbcrlf
r=r & ".xl24" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:11.0pt;" & vbcrlf
r=r & "	font-weight:700;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	background:silver;" & vbcrlf
r=r & "	mso-pattern:auto none;}" & vbcrlf
r=r & ".xl25" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:11.0pt;" & vbcrlf
r=r & "	font-weight:700;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	border:.5pt solid black;" & vbcrlf
r=r & "	background:silver;" & vbcrlf
r=r & "	mso-pattern:auto none;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl26" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:11.0pt;" & vbcrlf
r=r & "	font-weight:700;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	border-top:.5pt solid black;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:none;" & vbcrlf
r=r & "	background:silver;" & vbcrlf
r=r & "	mso-pattern:auto none;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl27" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;}" & vbcrlf
r=r & ".xl28" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:11.0pt;" & vbcrlf
r=r & "	font-weight:700;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl29" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:none;}" & vbcrlf
r=r & ".xl30" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:none;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:none;}" & vbcrlf
r=r & ".xl31" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:none;}" & vbcrlf
r=r & ".xl32" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	vertical-align:middle;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl33" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	vertical-align:middle;" & vbcrlf
r=r & "	border-top:.5pt solid black;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl34" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	vertical-align:middle;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl35" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	vertical-align:middle;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	background:red;" & vbcrlf
r=r & "	mso-pattern:auto none;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl36" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	vertical-align:middle;" & vbcrlf
r=r & "	border-top:.5pt solid black;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	background:red;" & vbcrlf
r=r & "	mso-pattern:auto none;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl37" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	vertical-align:middle;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	background:red;" & vbcrlf
r=r & "	mso-pattern:auto none;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl38" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	vertical-align:top;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl39" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	vertical-align:top;" & vbcrlf
r=r & "	border-top:.5pt solid black;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl40" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	vertical-align:top;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl41" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	mso-number-format:'General Date';" & vbcrlf
r=r & "	vertical-align:top;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl42" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	mso-number-format:'General Date';" & vbcrlf
r=r & "	vertical-align:top;" & vbcrlf
r=r & "	border-top:.5pt solid black;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl43" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:9.0pt;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	mso-number-format:'General Date';" & vbcrlf
r=r & "	vertical-align:top;" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl44" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:11.0pt;" & vbcrlf
r=r & "	font-weight:700;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	border-top:.5pt solid black;" & vbcrlf
r=r & "	border-right:none;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl45" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:11.0pt;" & vbcrlf
r=r & "	font-weight:700;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	border-top:.5pt solid black;" & vbcrlf
r=r & "	border-right:none;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:none;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl46" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	font-size:11.0pt;" & vbcrlf
r=r & "	font-weight:700;" & vbcrlf
r=r & "	font-family:Arial, sans-serif;" & vbcrlf
r=r & "	mso-font-charset:0;" & vbcrlf
r=r & "	text-align:center;" & vbcrlf
r=r & "	border-top:.5pt solid black;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:none;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl47" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	vertical-align:top;" & vbcrlf
r=r & "     mso-number-format:'\[<=9999999\]\#\#\#\\-\#\#\#\#\;\\\(\#\#\#\\\)\\ \#\#\#\\-\#\#\#\#';" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:none;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & ".xl48" & vbcrlf
r=r & "	{mso-style-parent:style0;" & vbcrlf
r=r & "	vertical-align:top;" & vbcrlf
r=r & " mso-number-format:'\[<=9999999\]\#\#\#\\-\#\#\#\#\;\\\(\#\#\#\\\)\\ \#\#\#\\-\#\#\#\#';" & vbcrlf
r=r & "	border-top:none;" & vbcrlf
r=r & "	border-right:.5pt solid black;" & vbcrlf
r=r & "	border-bottom:.5pt solid black;" & vbcrlf
r=r & "	border-left:.5pt solid black;" & vbcrlf
r=r & "	white-space:normal;}" & vbcrlf
r=r & "-->" & vbcrlf
r=r & "</style>" & vbcrlf
r=r & "<!--[if gte mso 9]><xml>" & vbcrlf
r=r & " <x:ExcelWorkbook>" & vbcrlf
r=r & "  <x:ExcelWorksheets>" & vbcrlf
r=r & "   <x:ExcelWorksheet>" & vbcrlf
r=r & "    <x:Name>" & TicketCount & " Ticket(s)" & "</x:Name>" & vbcrlf
r=r & "    <x:WorksheetOptions>" & vbcrlf
r=r & "     <x:Print>" & vbcrlf
r=r & "      <x:ValidPrinterInfo/>" & vbcrlf
r=r & "      <x:PaperSizeIndex>5</x:PaperSizeIndex>" & vbcrlf
r=r & "      <x:Scale>89</x:Scale>" & vbcrlf
r=r & "      <x:HorizontalResolution>600</x:HorizontalResolution>" & vbcrlf
r=r & "      <x:VerticalResolution>600</x:VerticalResolution>" & vbcrlf
r=r & "     </x:Print>" & vbcrlf
r=r & "     <x:PageBreakZoom>60</x:PageBreakZoom>" & vbcrlf
r=r & "     <x:Selected/>" & vbcrlf
r=r & "     <x:DoNotDisplayGridlines/>" & vbcrlf
r=r & "     <x:LeftColumnVisible>5</x:LeftColumnVisible>" & vbcrlf

r=r & "     <x:ProtectContents>False</x:ProtectContents>" & vbcrlf
r=r & "     <x:ProtectObjects>False</x:ProtectObjects>" & vbcrlf
r=r & "     <x:ProtectScenarios>False</x:ProtectScenarios>" & vbcrlf
r=r & "    </x:WorksheetOptions>" & vbcrlf
r=r & "   </x:ExcelWorksheet>" & vbcrlf
r=r & "  </x:ExcelWorksheets>" & vbcrlf
r=r & "  <x:WindowHeight>9720</x:WindowHeight>" & vbcrlf
r=r & "  <x:WindowWidth>15195</x:WindowWidth>" & vbcrlf
r=r & "  <x:WindowTopX>0</x:WindowTopX>" & vbcrlf
r=r & "  <x:WindowTopY>30</x:WindowTopY>" & vbcrlf
r=r & "  <x:ProtectStructure>False</x:ProtectStructure>" & vbcrlf
r=r & "  <x:ProtectWindows>False</x:ProtectWindows>" & vbcrlf
r=r & " </x:ExcelWorkbook>" & vbcrlf
r=r & "</xml><![endif]-->" & vbcrlf
r=r & "</head>" & vbcrlf
r=r & "" & vbcrlf
r=r & "<body link=blue vlink=purple>" & vbcrlf
r=r & "" & vbcrlf
r=r & "<table x:str border=0 cellpadding=0 cellspacing=0 width=1329 style='border-collapse:" & vbcrlf
r=r & " collapse;table-layout:fixed;width:1000pt'>" & vbcrlf
r=r & " <col width=69 style='mso-width-source:userset;mso-width-alt:2523;width:52pt'>" & vbcrlf
r=r & " <col width=54 style='mso-width-source:userset;mso-width-alt:1974;width:41pt'>" & vbcrlf
r=r & " <col width=61 style='mso-width-source:userset;mso-width-alt:2230;width:46pt'>" & vbcrlf
r=r & " <col width=100 style='mso-width-source:userset;mso-width-alt:3657;width:75pt'>" & vbcrlf
r=r & " <col width=122 style='mso-width-source:userset;mso-width-alt:4461;width:92pt'>" & vbcrlf
r=r & " <col width=82 style='mso-width-source:userset;mso-width-alt:2998;width:62pt'>" & vbcrlf
r=r & " <col width=42 style='mso-width-source:userset;mso-width-alt:1536;width:32pt'>" & vbcrlf
r=r & " <col width=94 style='mso-width-source:userset;mso-width-alt:3437;width:71pt'>" & vbcrlf
r=r & " <col width=80 style='mso-width-source:userset;mso-width-alt:2925;width:60pt'>" & vbcrlf
r=r & " <col width=86 style='mso-width-source:userset;mso-width-alt:3145;width:65pt'>" & vbcrlf
r=r & " <col width=68 style='mso-width-source:userset;mso-width-alt:2486;width:51pt'>" & vbcrlf
r=r & " <col width=91 style='mso-width-source:userset;mso-width-alt:3328;width:68pt'>" & vbcrlf
r=r & " <col width=90 style='mso-width-source:userset;mso-width-alt:3291;width:68pt'>" & vbcrlf
r=r & " <col width=200 style='mso-width-source:userset;mso-width-alt:7314;width:150pt'>" & vbcrlf

'column headers
r=r & " <tr class=xl24 height=40 style='height:30.0pt'>" & vbcrlf
r=r & "  <td height=40 class=xl25 width=69 style='height:30.0pt;width:52pt'>Ticket#</td>" & vbcrlf
r=r & "  <td class=xl26 width=54 style='width:41pt'>Emer.</td>" & vbcrlf
r=r & "  <td class=xl26 width=61 style='width:46pt'>Acct#</td>" & vbcrlf
r=r & "  <td class=xl26 width=100 style='width:75pt'>Name</td>" & vbcrlf
r=r & "  <td class=xl26 width=122 style='width:92pt'>Address</td>" & vbcrlf
r=r & "  <td class=xl26 width=82 style='width:62pt'>City</td>" & vbcrlf
r=r & "  <td class=xl26 width=42 style='width:32pt'>Zip</td>" & vbcrlf
r=r & "  <td class=xl26 width=94 style='width:71pt'>Phone</td>" & vbcrlf
r=r & "  <td class=xl26 width=80 style='width:60pt'>Appliance</td>" & vbcrlf
r=r & "  <td class=xl26 width=86 style='width:65pt'>Started</td>" & vbcrlf
r=r & "  <td class=xl26 width=68 style='width:51pt'>Status</td>" & vbcrlf
r=r & "  <td class=xl26 width=91 style='width:68pt'>Given To</td>" & vbcrlf
r=r & "  <td class=xl26 width=90 style='width:68pt'>Dispatched Time</td>" & vbcrlf
r=r & "  <td class=xl26 width=200 style='width:150pt'>Ticket History</td>" & vbcrlf
r=r & " </tr>" & vbcrlf

'report body
if listlength=-1 then r=r & "(No Tickets Found For This Time Period)"
for y=0 to listlength

 'customer information
 r=r & " <tr class=xl27 height=16 style='height:12.0pt'>" & vbcrlf
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " height=144 class=xl33 width=69 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  height:108.0pt;border-top:none;width:52pt' x:num>" & entrys(0,y) & "</td>" & vbcrlf 		'ticket#
	if entrys(6,y)="Yes" then
		color="#FF0000"
	else
		color="#FFFFFF"
	end if
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl36 width=54 style='border-bottom:.5pt solid black; " & vbcrlf
 r=r & "  border-top:none;width:41pt; background-color:" & color & "'>" & entrys(6,y) & "</td>" & vbcrlf	 'emergency
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 align=right width=61 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:46pt' x:num>" & entrys(7,y) & "</td>" & vbcrlf 				'acct#
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 width=100 style='border-bottom:.5pt solid black;" & vbcrlf 
 r=r & "  border-top:none;width:75pt'>" & entrys(8,y) & "</td>" & vbcrlf				 'name
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 width=122 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:92pt'>" & entrys(9,y) & "</td>" & vbcrlf				 'address
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 width=82 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:62pt'>" & entrys(10,y) & "</td>" & vbcrlf 				'city
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 align=right width=42 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:32pt' x:num>" & entrys(11,y) & "</td>" & vbcrlf 			'zip
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl48 align=right width=94 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:71pt' x:num='" & entrys(12,y) & "'>" & entrys(12,y) & "</td>" & vbcrlf	'phone

 'ticket information
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 width=80 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:74pt'>" & entrys(5,y) & "</td>" & vbcrlf				'appliance
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl42 align=right width=86 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:65pt' x:num='" & entrys(3,y) & "'>" & entrys(3,y) & "</td>" & vbcrlf	'created date
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 width=68 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:51pt'>" & entrys(1,y) & "</td>" & vbcrlf				'status
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 width=91 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:68pt'>" & entrys(2,y) & "</td>" & vbcrlf				'given to
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl42 align=right width=90 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:68pt' x:num='" & entrys(4,y) & "'>" & entrys(4,y) & "</td>" & vbcrlf	'completed

 'ticket history
 if clng(entrys(14,y))>1 then 
	plural="s"
 else
	plural=""
 end if
 r=r & "  <td " & ((clng(entrys(14,y))*3)+1) & " class=xl39 width=200 style='border-bottom:.5pt solid black;" & vbcrlf
 r=r & "  border-top:none;width:150pt'>" & entrys(14,y) & " call" & plural & "<br>" & vbcrlf
 r=r & entrys(13,y) & vbcrlf
 r=r & "  </td>" & vbcrlf									'ticket history
 r=r & " </tr>" & vbcrlf
next

r=r & " <tr height=20 style='height:15.0pt'>" & vbcrlf
r=r & "  <td height=20 class=xl28 width=79 style='height:15.0pt;width:59pt'>" & ticketcount & " Tickets</td>" & vbcrlf	'ticket count
r=r & "  <td colspan=12 style='mso-ignore:colspan'></td>" & vbcrlf
r=r & "  <td class=xl29>&nbsp;</td>" & vbcrlf
r=r & " </tr>" & vbcrlf
r=r & " <tr height=40 style='mso-height-source:userset;height:30.0pt'>" & vbcrlf
r=r & "  <td colspan=4 height=40 class=xl44 width=303 style='border-right:.5pt solid black;" & vbcrlf
r=r & "  height:30.0pt;width:227pt'>" & Fromfull & " - " & Tofull & "</td>" & vbcrlf

r=r & " </tr>" & vbcrlf
r=r & " <![if supportMisalignedColumns]>" & vbcrlf
r=r & " <tr height=0 style='display:none'>" & vbcrlf
r=r & "  <td width=79 style='width:59pt'></td>" & vbcrlf
r=r & "  <td width=63 style='width:47pt'></td>" & vbcrlf
r=r & "  <td width=61 style='width:46pt'></td>" & vbcrlf
r=r & "  <td width=100 style='width:75pt'></td>" & vbcrlf
r=r & "  <td width=122 style='width:92pt'></td>" & vbcrlf
r=r & "  <td width=94 style='width:71pt'></td>" & vbcrlf
r=r & "  <td width=42 style='width:32pt'></td>" & vbcrlf
r=r & "  <td width=85 style='width:64pt'></td>" & vbcrlf
r=r & "  <td width=98 style='width:74pt'></td>" & vbcrlf
r=r & "  <td width=97 style='width:73pt'></td>" & vbcrlf
r=r & "  <td width=68 style='width:51pt'></td>" & vbcrlf
r=r & "  <td width=114 style='width:86pt'></td>" & vbcrlf
r=r & "  <td width=106 style='width:80pt'></td>" & vbcrlf
r=r & "  <td width=200 style='width:150pt'></td>" & vbcrlf
r=r & " </tr>" & vbcrlf
r=r & " <![endif]>" & vbcrlf
r=r & "</table>" & vbcrlf
r=r & "" & vbcrlf
r=r & "</body>" & vbcrlf
r=r & "" & vbcrlf
r=r & "</html>" & vbcrlf

results=r
'end create report
		end if	
		set fs=server.CreateObject("scripting.filesystemobject")
		folder="reports"
		set filepath=fs.getfolder(server.MapPath("reports"))
		filename=replace(filename,"/","-") & ".xls"
		filename=replace(filename,":",".")
		set reportfile=filepath.createtextfile(filename,"true")
		reportfile.write(results)
		%>
		<script type="text/javascript">
		alert("<%= filename %> sucessfully created!")
		fromfull="<%= fromfull %>"
		tofull="<%= tofull %>"
		tc="<%= ticketcount %>"
		window.location.href="SaveReport.asp?fromfull=" + fromfull + "&tofull=" + tofull + "&ticketcount=" + tc
		</script>	
<%	
end select
if err.number<>0 then errorhandler("no")
 %>

        
</body>
</html>
